package com.jingbo.servlet;

import com.jingbo.DAO.User.Adduserimpl;
import com.jingbo.service.register.registeruserimpl;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author jiangjingbo
 * @version V1.0
 * @Project java2203
 * @Package com.jingbo.servlet
 * @Description:
 * @Date 2022/5/27 13:44
 */
@WebServlet("/login")
public class loginUser extends  BeanServlet {
    public  String login(HttpServletRequest request, HttpServletResponse response){
        String username = request.getParameter("username");
        String pwd = request.getParameter("pwd");
        if(username==null||pwd==null){
            return  "forward:"+request.getContextPath()+"/login.jsp";
        }
        registeruserimpl registeruserimpl = new registeruserimpl(new Adduserimpl());
        boolean user = registeruserimpl.selectUser(username, pwd);
        request.getSession().setAttribute("name",username);
        if(user){
            return  "forward:/selectAll?method=selectAll";
        }else {
            return  "forward:"+request.getContextPath()+"/login.jsp";
        }
    }
}
